home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / analyze / analyzePageAllocation.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.9 KB  |  223 lines

  1. /*
  2.  *   $RCSfile: analyzePageAllocation.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:33 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "semaphore.h"
  53. #include "latch.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "volume.h"
  58. #include "openlog.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "log.h"
  63. #include "bitmap.h"
  64. #include "log_extfuncs.h"
  65. #include "recover_intfuncs.h"
  66. #include "trans_extfuncs.h"
  67. #include "analyze_extfuncs.h"
  68. #include "thread_globals.h"
  69. #include "trans_globals.h"
  70.  
  71.  
  72. /* 
  73.  *    Determine the bitmap pages affected by allocation and deallocation
  74.  *    of pages
  75.  */
  76.  
  77.  void
  78. analyzePageAllocation (
  79.  
  80.     LOGRECORDHDR        *record 
  81. )
  82. {
  83.  
  84.     register int        i;
  85.     PID                    *pid;
  86.     int                    numPages;
  87.     PID                    bitmapPid;
  88.     PID                    headerPid;
  89.     DIRTYPAGEINFO        *dirtyInfo;
  90.     int                    bitmapPageCount;
  91.     LRC                    *lrcList;
  92.     LRC                    *headerLRC;     /* volume header lrc */
  93.     SHORTPID            allocPage;
  94.     PAGEALLOCINFO        *pageAllocInfo;
  95.     
  96.  
  97.     TRACE(TR_IO, TR_LEVEL_1);
  98.  
  99.     /*
  100.      *    get a pointer to the page allocation info and the allocated pid
  101.      */
  102.     pageAllocInfo = (PAGEALLOCINFO*) GET_LOG_IMAGE(record, 0);
  103.     pid = (PID *) GET_LOG_IMAGE(record, 1);
  104.     numPages = GET_LOG_IMAGE_SIZE(record, 1) / sizeof(PID);
  105.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("pid:%d", pid->page));
  106.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("page2size:%d", pageAllocInfo->page2size));
  107.  
  108.     /*
  109.      *    If the pages are being deallocated, flag them in the
  110.      *    dirty page table.  If they are being allocated,
  111.      *    then that is an internal error for now since no reallocation
  112.      *    of pages within a transaction is allowed.
  113.      */
  114.     for (i = 0; i < numPages; i++) {
  115.         if ((dirtyInfo = searchDirtyPageTable( &(pid[i]) )) != NULL)    {
  116.             if (record->action == LOG_ACTION_DEALLOCATE_PAGE) {
  117.                 /*
  118.                  * flag the page as deallocated
  119.                  */
  120.                 SM_ASSERT(LEVEL_3, !(dirtyInfo->flags & DPT_DEALLOC) );
  121.                 dirtyInfo->flags |= DPT_DEALLOC;
  122.                 dirtyInfo->tid = record->tid;
  123.             } else {
  124.                 SM_ASSERT(LEVEL_3, !(dirtyInfo->flags & DPT_DEALLOC) );
  125.             }
  126.             
  127.         }
  128.     }
  129.  
  130.     /*
  131.      *    get a pointer to the lrc list for the bitmap pages, and 
  132.      *    calculate the number of bitmap pages involved, base on
  133.      *    the length of the list
  134.      */
  135.     lrcList = (LRC *) GET_LOG_IMAGE(record, 2);
  136.     bitmapPageCount = GET_LOG_IMAGE_SIZE(record, 2) / sizeof(LRC);
  137.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("lrc list size:%d", bitmapPageCount));
  138.  
  139.     /*
  140.      *    get a pointer to the volume header lrc and the pid of the
  141.      *    first bitmap page
  142.      */
  143.     headerLRC = &(pageAllocInfo->headerLRC);
  144.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("header lrc:%d", headerLRC->count));
  145.  
  146.     /*
  147.      *    construct the bitmap pid
  148.      */
  149.     bitmapPid.volid = pid->volid;
  150.  
  151.     /*
  152.      *    check the pages for the dirty list
  153.      */
  154.     allocPage = pid->page;     /* first allocated page    */
  155.     for (i = 0; i < bitmapPageCount; i++)    {
  156.  
  157.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("block pid:%d", allocPage));
  158.  
  159.         /*
  160.          *    calculate the bitmap page
  161.          */
  162.         bitmapPid.page = BIT_TO_PAGE(allocPage) + pageAllocInfo->firstBitmapPage;
  163.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("bitmap page:%d", bitmapPid.page));
  164.         /*
  165.          *    Calculate index of the first allocated page on the next 
  166.          *    bitmap page 
  167.          */
  168.         allocPage += BITS_IN_PAGE - BIT_IN_PAGE(allocPage);
  169.  
  170.         /*
  171.          *    check to see if the page is in the dirty list
  172.          */
  173.         if ((dirtyInfo = searchDirtyPageTable( &bitmapPid )) == NULL)    {
  174.  
  175.             /*
  176.              *    create a new entry
  177.              */
  178.             if ((dirtyInfo = insertDirtyPageTable( &bitmapPid )) == NULL)    {
  179.  
  180.                 SM_ERROR(TYPE_FATAL, esmINTERNAL);
  181.             }
  182.  
  183.             /*
  184.              *    update the information
  185.              */
  186.             dirtyInfo->lsn = record->recordLSN;
  187.             dirtyInfo->lrc = lrcList[i];
  188.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("page lsn:%d, lrc:%d", 
  189.                     dirtyInfo->lsn.offset, dirtyInfo->lrc.count));
  190.         }
  191.     }
  192.  
  193.     /*
  194.      *    Analyze the lrc on the header page, first get the header
  195.      *    page pid.
  196.      */
  197.     headerPid.page = pageAllocInfo->volumeHdrPage;
  198.     headerPid.volid = pid->volid;
  199.  
  200.     /*
  201.      *  check to see if the header page is in the dirty list
  202.      */
  203.     if ((dirtyInfo = searchDirtyPageTable(&headerPid)) == NULL)    {
  204.  
  205.         /*
  206.          *  create a new entry
  207.          */
  208.         if ((dirtyInfo = insertDirtyPageTable(&headerPid)) == NULL)    {
  209.  
  210.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  211.         }
  212.  
  213.         /*
  214.          *  update the information
  215.          */
  216.         dirtyInfo->lsn = record->recordLSN;
  217.         dirtyInfo->lrc = *headerLRC;
  218.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("lsn:%d,lrc:%d", 
  219.                 dirtyInfo->lsn.offset, dirtyInfo->lrc.count));
  220.     }
  221.  
  222. }
  223.